package com.joint.web.action.com;

import com.fz.us.base.bean.BaseEnum;
import com.fz.us.base.bean.BaseEnum.StateEnum;
import com.fz.us.base.bean.Pager;
import com.fz.us.base.service.memcached.SpyMemcachedClient;
import com.fz.us.base.util.LogUtil;
import com.fz.us.base.util.mapper.BeanMapper;
import com.fz.us.dict.bean.DictBean;
import com.fz.us.dict.entity.Dict;
import com.fz.us.dict.service.DictService;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.joint.base.entity.Company;
import com.joint.base.entity.FileManage;
import com.joint.base.entity.Users;
import com.joint.base.entity.system.Locations;
import com.joint.base.service.UsersService;
import com.joint.base.util.DataUtil;
import com.joint.base.util.FileUtil;
import com.joint.core.entity.ProBack;
import com.joint.core.entity.ProInfo;
import com.joint.core.service.ProBackService;
import com.joint.core.service.ProInfoService;
import com.joint.web.action.BaseAdminAction;
import com.mongodb.gridfs.GridFSDBFile;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.ParentPackage;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by xh on 2015/3/2.
 */
@ParentPackage("com")
public class AjaxProBackAction extends BaseAdminAction {

    @Resource
    private ProBackService proBackService;
    @Resource
    private ProInfoService proInfoService;
    @Resource
    private DictService dictService;
    @Resource
    private UsersService usersService;
    @Resource
    private SpyMemcachedClient spyMemcachedClient;

    //项目类别	选数据字典
    protected ArrayList<Map<String,Object>> typesArrayList;

    protected ProBack proBack;
    private Set<Users> notice;
    private List<ProInfo> proInfoList;
    private List<Users> usersList;
    private List<Dict> probackType;

    private String keyId;
    private String dictId;
    private String proInfoId;
    private String noticeId;
    private String address;
    private String probackTypeId;

    private String createDate;
    private String content;
    private String mark;
    private int regular;
    private Date backDate;
    private String name;
    private String start;
    private String end;

    //视图类型：1--独立视图，2--tab页中的视图
    private String viewType = "1";

    private Set<String> imgUrl;


    private String now;
    public String options(){
        String html = "<div style='position:relative;'><span style='margin-left:2px;width:18px;overflow:hidden;'>";
        html = html + "<select id='searchselect' style='height:21px;width:100%;margin-left:-2px;' onchange='this.parentNode.nextSibling.value=this.options[this.selectedIndex].text;'>";
        html = html + "<option value=''>请选择...</option>";
        List<ProInfo> thisList = (List<ProInfo>)proInfoService.findByPager(null).getList();
        for (ProInfo pinfo:thisList){
            html = html + "<option value='"+pinfo.getName()+"'>"+pinfo.getName()+"</option>";
        }
        html = html + "</select></span>";
        html = html + "<input type='text' style='width:90%;position:absolute;left:0px;' value='请选择...' id='sinputname' onkeydown='EnterPress(event)' onkeydown='EnterPress()'></div>";
        return ajaxText(html);
    }

    public String list(){

        pager = new Pager();
        pager.setPageSize(rows);
        pager.setPageNumber(page);
        pager.setOrderBy("createDate");
        pager.setOrderType(BaseEnum.OrderType.desc);
        if(StringUtils.isNotEmpty(sidx)&&BaseEnum.OrderType.valueOf(sord)!=null){
            pager.setOrderBy(sidx);
            pager.setOrderType(BaseEnum.OrderType.valueOf(sord));
        }

        Company com = usersService.getCompanyByUser();
        Users loginuser=usersService.getLoginInfo();
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("state",StateEnum.Enable);


        params = getSearchFilterParams(_search,params,filters);

//        if (StringUtils.isNotEmpty(proInfoId)){
//
//            ProInfo proInfo = proInfoService.get(proInfoId);
//            params.put("proInfo",proInfo);
//            params.put("company",com);
//            pager = proBackService.findByPagerAndCompany(pager,null,com,params);
//        }else{
//            pager = proBackService.findByPagerAndLimit(pager,loginuser,com,params);
//           // pager=proBackService.findByPagerAndCompany(pager,null,com,params);
//        }

        if(StringUtils.isNotEmpty(proInfoId)){
            ProInfo proinfo=proInfoService.get(proInfoId);
            params.put("proInfo",proinfo);
            params.put("company",com);
        }

        if(StringUtils.isNotEmpty(probackTypeId)){
            Dict dict=dictService.get(probackTypeId);
            params.put("category",dict);
        }

        if(StringUtils.isNotEmpty(start) || StringUtils.isNotEmpty(end)){
            Date endDate = DataUtil.getAfterDay(DataUtil.StringToDate(end, "yyyy-MM-dd"), 1);
            pager=proBackService.findByPagerAndCompany(pager,"createDate", DataUtil.StringToDate(start, "yyyy-MM-dd"),endDate,null,com,params);
        }else{
            pager=proBackService.findByPagerAndCompany(pager,null,null,params);
        }
        if(StringUtils.isEmpty(proInfoId) && StringUtils.isEmpty(start) && StringUtils.isEmpty(end)) {
            pager=proBackService.findByPagerAndLimit(pager,loginuser,com,params);
        }

        List<ProBack> proBackList= (List<ProBack>) (pager.getTotalCount()>0?pager.getList():Lists.newArrayList());


        List<JSONObject> dataRows=new ArrayList<JSONObject>();
        Map<String, Object> data = new HashMap<String, Object>();
        Map<String,Object> rMap;
        if(proBackList!=null && proBackList.size()>0){
            for(ProBack proBack:proBackList){

                rMap = new HashMap<String, Object>();
                rMap.put("id",proBack.getId());
                rMap.put("proname", proBack.getProInfo().getName());
                rMap.put("backDate", DataUtil.DateToString(proBack.getBackDate(), "yyyy-MM-dd"));
                rMap.put("category",proBack.getCategory().getName());
                rMap.put("content",proBack.getContent());
                rMap.put("creater",proBack.getCreater().getName());
                if(proBack.getRegular()==1){
                    rMap.put("regular", "是");
                }else{
                    rMap.put("regular", "否");
                }

                Set<Users> users = proBack.getNotice();
                String men = "";
                for (Users user:users){
                    if(user.getState()==StateEnum.Delete){
                        continue;
                    }
                    men += user.getName() + ",";
                }
                if (StringUtils.isNotEmpty(men)){
                    men = men.substring(0, men.length()-1);
                }
                rMap.put("notice",men);

                dataRows.add(JSONObject.fromObject(rMap));
            }
        }
        long total =pager.getTotalCount();
        if(total%rows==0){
            total = total/rows;
        }else{
            if(total<rows){
                total = 1;
            }else{
                total = total/rows + 1;
            }
        }
        data.put("dataRows",dataRows);
        data.put("page",page);
        data.put("rows",rows);
        data.put("total",total);
        data.put("records",pager.getTotalCount());
        return  ajaxJson(JSONObject.fromObject(data).toString());
    }

    public String tablist(){
        pager = new Pager();
        pager.setPageSize(rows);
        pager.setPageNumber(page);
        pager.setOrderBy("createDate");
        pager.setOrderType(BaseEnum.OrderType.desc);
        if(StringUtils.isNotEmpty(sidx)&&BaseEnum.OrderType.valueOf(sord)!=null){
            pager.setOrderBy(sidx);
            pager.setOrderType(BaseEnum.OrderType.valueOf(sord));
        }

        Company com = usersService.getCompanyByUser();
        Users loginuser=usersService.getLoginInfo();
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("state",StateEnum.Enable);

        params.put("name", name);
        params = getSearchFilterParams(_search,params,filters);

        if (StringUtils.isNotEmpty(proInfoId)){
            ProInfo proInfo = proInfoService.get(proInfoId);
            params.put("proInfo",proInfo);
            params.put("company",com);
            pager = proBackService.findByPagerAndCompany(pager,null,com,params);
        }else{
            pager = proBackService.findByPagerAndLimit(pager,loginuser,com,params);
            // pager=proBackService.findByPagerAndCompany(pager,null,com,params);
        }
        List<ProBack> proBackList= (List<ProBack>) (pager.getTotalCount()>0?pager.getList():Lists.newArrayList());


        List<JSONObject> dataRows=new ArrayList<JSONObject>();
        Map<String, Object> data = new HashMap<String, Object>();
        Map<String,Object> rMap;
        if(proBackList!=null && proBackList.size()>0){
            for(ProBack proBack:proBackList){

                rMap = new HashMap<String, Object>();
                rMap.put("id",proBack.getId());
                rMap.put("proname", proBack.getProInfo().getName());
                rMap.put("backDate", DataUtil.DateToString(proBack.getBackDate(), "yyyy-MM-dd"));
                rMap.put("category",proBack.getCategory().getName());
                rMap.put("content",proBack.getContent());
                rMap.put("creater",proBack.getCreater().getName());
                if(proBack.getRegular()==1){
                    rMap.put("regular", "是");
                }else{
                    rMap.put("regular", "否");
                }

                Set<Users> users = proBack.getNotice();
                String men = "";
                for (Users user:users){
                    if(user.getState()==StateEnum.Delete){
                        continue;
                    }
                    men += user.getName() + ",";
                }
                if (StringUtils.isNotEmpty(men)){
                    men = men.substring(0, men.length()-1);
                }
                rMap.put("notice",men);

                dataRows.add(JSONObject.fromObject(rMap));
            }
        }
        long total =pager.getTotalCount();
        if(total%rows==0){
            total = total/rows;
        }else{
            if(total<rows){
                total = 1;
            }else{
                total = total/rows + 1;
            }
        }
        data.put("dataRows",dataRows);
        data.put("page",page);
        data.put("rows",rows);
        data.put("total",total);
        data.put("records",pager.getTotalCount());
        return  ajaxJson(JSONObject.fromObject(data).toString());
    }

    public String warn(){
        return  "warn";
    }

    public String warnlist(){

        pager = new Pager();
        pager.setPageSize(rows);
        pager.setPageNumber(page);
        pager.setOrderBy("backDate");
        pager.setOrderType(BaseEnum.OrderType.desc);
        if(StringUtils.isNotEmpty(sidx)&&BaseEnum.OrderType.valueOf(sord)!=null){
            pager.setOrderBy(sidx);
            pager.setOrderType(BaseEnum.OrderType.valueOf(sord));
        }
        Company com = usersService.getCompanyByUser();
        Users loginuser=usersService.getLoginInfo();

        Map<String,Object> params = new HashMap<String,Object>();
        params.put("company",com);
        params.put("state",new StateEnum[]{StateEnum.Enable});
        params.put("regular",0);
        params = getSearchFilterParams(_search,params,filters);

        pager = proBackService.findByPagerAndLimit(pager,loginuser,com,params);

        //pager = proBackService.findByPagerAndCompany(pager, null, com, params);
        List<ProBack> proBackList= (List<ProBack>) (pager.getTotalCount()>0?pager.getList():Lists.newArrayList());
        List<JSONObject> dataRows=new ArrayList<JSONObject>();
        Map<String, Object> data = new HashMap<String, Object>();
        Map<String,Object> rMap;
        for(ProBack proBack:proBackList){

            rMap = new HashMap<String, Object>();
            rMap.put("id",proBack.getId());
            rMap.put("proname", proBack.getProInfo().getName());
            rMap.put("backDate", DataUtil.DateToString(proBack.getBackDate(), "yyyy-MM-dd"));
            rMap.put("category",proBack.getCategory().getName());
            rMap.put("content",proBack.getContent());
            rMap.put("creater",proBack.getCreater().getName());
            rMap.put("regular", "否");

            Set<Users> users = proBack.getNotice();
            String men = "";
            for (Users user:users){
                men += user.getName() + ",";
            }
            if (StringUtils.isNotEmpty(men)){
                men = men.substring(0, men.length()-1);
            }
            rMap.put("notice",men);

            dataRows.add(JSONObject.fromObject(rMap));
        }
        long total =pager.getTotalCount();
        if(total%rows==0){
            total = total/rows;
        }else{
            if(total<rows){
                total = 1;
            }else{
                total = total/rows + 1;
            }
        }
        data.put("dataRows",dataRows);
        data.put("page",page);
        data.put("rows",rows);
        data.put("total",total);
        data.put("records",pager.getTotalCount());
        return  ajaxJson(JSONObject.fromObject(data).toString());
    }

    public String view(){
        pager=new Pager(0);
        Pager pager2 = new Pager(0);
        pager2.setPageNumber(0);
        Map<String,Object> params= Maps.newHashMap();
        params.put("state",StateEnum.Enable);
        Users loginUser=usersService.getLoginInfo();
        Company com=usersService.getCompanyByUser();
        pager=proInfoService.findByPagerAndLimit(new Pager(),loginUser,com,params);
        pager2 =proInfoService.findByPagerAndLimit( pager2,loginUser,com,params);
        proInfoList= (List<ProInfo>) (pager2.getTotalCount()>0?pager2.getList():Lists.newArrayList());
        probackType=dictService.listDefinedAll(DictBean.DictEnum.valueOf("ProBackCategory"), usersService.getCompanyByUser().getId());
        return "view";
    }

    public String tabview(){
        return "tabview";
    }

    public String read(){
        //LogUtil.info("keyId:" + keyId);
        if(StringUtils.isNotEmpty(keyId)){
            proBack = proBackService.get(keyId);
            if(StringUtils.isNotEmpty(proBack.getLocationId())){
                Locations locations= locationsService.get(proBack.getLocationId());
                address=locationsService.getAddress(locations);
            }else{
                address="";
            }
            Set<FileManage> urls = proBack.getPicsUrl();

            if(null != urls){
                HttpServletRequest request = getRequest();
                String base = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
                //imgUrl
                imgUrl = Sets.newHashSet();
                for (FileManage fileManage : urls){
                    imgUrl.add(base + "/com/file.action?gridId="+fileManage.getGridId());
                }
            }
        }
        return "read";
    }

    public String input(){
        if (StringUtils.isNotEmpty(keyId)){
            proBack = proBackService.get(keyId);
        }

        Company company = usersService.getCompanyByUser();

        Map<String,Object> rMap = null;
        typesArrayList = new ArrayList<Map<String, Object>>();
        for(Dict typeObj:dictService.listFormDefinedEnable(DictBean.DictEnum.ProBackCategory, company.getId())){
            rMap = new HashMap<String, Object>();
            rMap.put("id",typeObj.getId());
            rMap.put("name",typeObj.getName());
            rMap.put("selected","");
            if(proBack!=null && proBack.getCategory()!=null) {
                if( proBack.getCategory().getId().equals(typeObj.getId())){
                    rMap.put("selected","selected");
                }
            }
            typesArrayList.add(rMap);
        }

        return  "input";
    }


    public String save(){
        //LogUtil.info("keyId:"+keyId);
        ProBack preBack = null;
        if(StringUtils.isNotEmpty(keyId)){
            proBack = proBackService.get(keyId);
            preBack = BeanMapper.map(proBack, ProBack.class);
        }else{
            proBack = new ProBack();
            proBack.setCreater(usersService.getLoginInfo());
        }
        proBack.setName("");
        if (StringUtils.isNotEmpty(dictId)){
            Dict dict = dictService.get(dictId);
            proBack.setCategory(dict);
        }
        if (StringUtils.isNotEmpty(proInfoId)){
            ProInfo proInfo = proInfoService.get(proInfoId);
            proBack.setProInfo(proInfo);
            proBack.setName(proInfo.getName());
        }
        //proBack.setCreateDate(DataUtil.StringToDate(backDate, "yyyy-MM-dd"));
        proBack.setBackDate(backDate);
        proBack.setContent(content);
        proBack.setMark(mark);
        proBack.setRegular(regular);

        if (StringUtils.isNotEmpty(noticeId)){
            String[] userIds = StringUtils.split(noticeId,",");
            Set<Users> group = new HashSet<Users>();
            for (String userId : userIds){
                if(StringUtils.isEmpty(userId)) continue;
                Users user = usersService.get(userId);
                group.add(user);
            }
            //LogUtil.info("group "+group.size());
            proBack.setNotice(group);
        }


        proBack.setCompany(usersService.getCompanyByUser());
        //proBackService.updateAndEnable(proBack,preBack);
        return ajaxHtmlCallback("200", "保存成功！","操作状态");
    }

    public String delete(){
        if(StringUtils.isEmpty(keyId)){
            return ajaxHtmlCallback("404", "请选择客户信息！","操作状态");
        }
        ProInfo proInfo = proInfoService.get(keyId);
        proInfo.setState(StateEnum.Delete);
        proInfoService.update(proInfo);
        return ajaxHtmlCallback("200", "删除成功！","操作状态");
    }

    /**
     * @date 2015-7-2
     * 按项目批量导出反馈数据rar
     * @throws IOException
     */
    public String exportAllData() throws IOException {
        boolean hasData = false;
        boolean hasDataFlag = false;
        Date today = new Date();
        String now = DataUtil.DateToString(today, "yyyyMMddHHmmss");
        pager = new Pager(0);
        Company com = usersService.getCompanyByUser();
        Users user = usersService.getLoginInfo();
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("state",new StateEnum[]{StateEnum.Enable});
        Pager pagerProInfo = proInfoService.findByPagerAndLimit(pager,user,com,params);
        List<ProInfo>  proInfoList= (List<ProInfo>) pagerProInfo.getList();
        LogUtil.info("项目个数:"+proInfoList.size());
        HttpServletRequest request = getRequest();
        String base = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
        List<String> dirlist = new ArrayList<String>();
        dirlist.add("/tmpfile/"+now+"/"+"反馈信息数据");

        if(StringUtils.isNotEmpty(proInfoId)){
            hasData = exportInfo(proInfoService.get(proInfoId),com,hasData,base,now);
        }else{
            for(ProInfo pro:proInfoList){
                hasData = exportInfo(pro,com,hasData,base,now);
                if(hasData){
                    hasDataFlag = true;
                }
            }
        }

        if(hasData || hasDataFlag){
            String filePath = "/tmpfile/"+now+"/反馈信息数据.zip";
            FileUtil.createZip(dirlist, filePath);
            return ajaxHtmlCallback("200", now,"操作状态");
        }

        return ajaxHtmlCallback("400", "您没有反馈信息","操作状态");

    }

    public boolean exportInfo(ProInfo pro,Company com,boolean hasData,String base,String now) throws IOException {
        pager = new Pager(0);
        Map<String,Object> paramsProBack = new HashMap<String,Object>();
        paramsProBack.put("proInfo",pro);
        paramsProBack.put("company",com);
        String filePath = pro.getName();
        Pager pagerProback =proBackService.findByPagerAndCompany(pager,null,null,paramsProBack);
        List<ProBack>  proBackList= (List<ProBack>) pagerProback.getList();
        LogUtil.info("反馈个数:"+  proBackList.size());
        for(ProBack back:proBackList){
            hasData = true;
            String cat =  back.getCategory().getName();
            String time = DataUtil.DateToString(back.getCreateDate(), "yyyy-MM-dd@HH：mm：ss") ;
            String pathname = "/tmpfile/"+now+"/"+"反馈信息数据/"+filePath+"/"+cat+"/"+time;
            File file = new File(pathname);
            FileUtil.makeDir(file);
            Set<FileManage> urls = back.getPicsUrl();
            if(null != urls){
                for (FileManage fileManage : urls){
                    String gridId = fileManage.getGridId();
                    // LogUtil.info (base + "/com/file!getFileName.action?gridId=" + fileManage.getGridId());
                    String filename = getFileName(gridId);
                   // System.out.println("filename:"+pathname+"/"+filename);
                    if(!filename.equals("error")){
                        FileUtil.getFileByUrl(base + "/com/file!readDoc.action?gridId=" + gridId, pathname + "/" + filename);
                    }

                }
            }

        }
        return hasData;
    }

    /**
     * 获得文件名称
     * @return
     */
    public String getFileName(String gridId){
        GridFSDBFile file = null;
        if (StringUtils.isNotEmpty(gridId)){
            file = gridFSGet(gridId);
            if(file == null){
                return "error";
            }
            return file.getFilename();
        }
        return "error";
    }

    public void download() throws IOException {
        String fileName = "反馈信息数据.zip";
        OutputStream out = null;
        HttpServletResponse response = getTheResponse();
        response.setContentType("text/plain;charset=UTF-8");
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setHeader("content-disposition", "attachment;filename="+ new String(fileName.getBytes(), "ISO8859-1"));
        OutputStream outputStream = response.getOutputStream();
        // System.out.println("filepath:"+URLDecoder.decode(filePath, "UTF-8"));
        String filePath = "/tmpfile/"+now+"/反馈信息数据.zip";
        InputStream inputStream = new FileInputStream(filePath);
        byte[] buffer = new byte[1024];
        int i = -1;
        while ((i = inputStream.read(buffer)) != -1) {
            outputStream.write(buffer, 0, i);
        }
        outputStream.flush();
        outputStream.close();
        inputStream.close();
        outputStream = null;
        //删除数据
        FileUtil.del("/tmpfile");
    }
    /*
    public String getChartData(){
        Date date = new Date();
        String now = DataUtil.DateToString(date, "yyyy-MM-dd");
        String[] daysInMonth = DataUtil.getMonthDays(now);
        List<String> timeline = new ArrayList<String>(Arrays.asList(daysInMonth));//横坐标
        pager = new Pager(0);
        Company com = usersService.getCompanyByUser();
        Users user = usersService.getLoginInfo();
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("state",new StateEnum[]{StateEnum.Enable});
        Pager pagerProInfo = proInfoService.findByPagerAndLimit(pager,user,com,params);
        List<ProInfo>  proInfoList= (List<ProInfo>) pagerProInfo.getList();
        List<String> xAxis = new ArrayList<String>();
       // LogUtil.info("项目个数:"+proInfoList.size());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf3 = new SimpleDateFormat("dd");
        String dateNowStr = sdf.format(date);
        //Calendar calNow = Calendar.getInstance();
        int index = 0;
        for(ProInfo pro:proInfoList){
            if(index % 2 == 0){
                xAxis.add(pro.getName());
            }else{
                xAxis.add("\n"+ pro.getName());
            }
            Map<String,Object> paramsProBack = new HashMap<String,Object>();
            paramsProBack.put("proInfo",pro);
            paramsProBack.put("company",com);
            Pager pagerProback = proBackService.findByPagerAndCompany(pager,null,null,paramsProBack);
            List<ProBack>  proBackList = (List<ProBack>) pagerProback.getList();
            for(ProBack back : proBackList ){
                Date createDate = back.getCreateDate();
                if(sdf.format(createDate).equals(dateNowStr)){
                    System.out.println("yes");
                    System.out.println(sdf3.format(createDate));
                }else{
                    System.out.println("no");
                }
            }
            for(String day:daysInMonth){
                String newDay = null;
                Date newDate = null;
                if(day.length() <2){
                    newDay  = dateNowStr+"-"+"0"+day;
                }else{
                    newDay  = dateNowStr+"-"+day;
                }

                try {
                    newDate = sdf2.parse(newDay);
                } catch (ParseException e) {
                    e.printStackTrace();
                }

               // System.out.println("proBackList.size:"+proBackList.size());
            }

            index++;
        }
        Map<String, Object> yMap = new HashMap<String, Object>();
        yMap.put("timeline", timeline);
        yMap.put("xAxis", xAxis);
        return ajaxJson(JSONObject.fromObject(yMap).toString());
    }*/


    private static List<String> printWeekdays() {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        List<String> listWeek = new ArrayList<String>();
        setToFirstDay(calendar);
        for (int i = 0; i < 7; i++) {
            listWeek.add(dateFormat.format(calendar.getTime())) ;
            calendar.add(Calendar.DATE, 1);
        }
        return listWeek;
    }

    private static void setToFirstDay(Calendar calendar) {
        while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
            calendar.add(Calendar.DATE, -1);
        }
    }
    public String getChartDataByWeek(){
        List<String> listWeek =  printWeekdays();
        Date date = new Date();
        String year = DataUtil.DateToString(date, "yyyy");
        String month = DataUtil.DateToString(date, "M");
        String day = DataUtil.DateToString(date, "dd");
        String now = DataUtil.DateToString(date, "yyyy-MM-dd");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdfy = new SimpleDateFormat("yyyy");
        SimpleDateFormat sdfm = new SimpleDateFormat("M");
        SimpleDateFormat sdfd = new SimpleDateFormat("dd");
        pager = new Pager(0);
        Company com = usersService.getCompanyByUser();

        Map<String,Object> paramsProBack = new HashMap<String,Object>();
        if(StringUtils.isNotEmpty(proInfoId)){
            ProInfo proInfo = proInfoService.get(proInfoId);
            paramsProBack.put("proInfo",proInfo);
        }
        paramsProBack.put("company",com);
        paramsProBack.put("regular",1);

        Pager pagerProback = proBackService.findByPagerAndCompany(pager,null,null,paramsProBack);
        List<ProBack>  proBackList = (List<ProBack>) pagerProback.getList();
        paramsProBack.put("regular",0);
        Pager pagerProback2 = proBackService.findByPagerAndCompany(pager,null,null,paramsProBack);
        List<ProBack>  proBackList2 = (List<ProBack>) pagerProback2.getList();
        List<JSONObject> seriesList = new  ArrayList<JSONObject>();
        Map<String, Object> xMap = new HashMap<String, Object>();
        Map<String, Object> rxMap = new HashMap<String, Object>();
        Integer[] data = new Integer[]{0,0,0,0,0,0,0};
        Integer[] data2 = new Integer[]{0,0,0,0,0,0,0};
        for(ProBack back:proBackList) {
            Date createDate = back.getCreateDate();
            String strDate = sdf.format(createDate);
            int index = listWeek.indexOf(strDate);
            if(index != -1){
                data[index] += 1;
            }
        }

        for(ProBack back:proBackList2) {
            Date createDate = back.getCreateDate();
            String strDate = sdf.format(createDate);
            int index = listWeek.indexOf(strDate);
            if(index != -1){
                data2[index] += 1;
            }
        }
        xMap.put("data",data);
        rxMap.put("data",data2);



        seriesList.add(JSONObject.fromObject(xMap));
        seriesList.add(JSONObject.fromObject(rxMap));
        Map<String, Object> oMap = new HashMap<String, Object>();
        oMap.put("series",seriesList);
        return ajaxJson(JSONObject.fromObject(oMap).toString());
    }



    public String getChartDataByYear(){
        Date date = new Date();
        String year = DataUtil.DateToString(date, "yyyy");
        String month = DataUtil.DateToString(date, "M");
        String day = DataUtil.DateToString(date, "dd");
        String now = DataUtil.DateToString(date, "yyyy-MM-dd");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdfy = new SimpleDateFormat("yyyy");
        SimpleDateFormat sdfm = new SimpleDateFormat("M");
        SimpleDateFormat sdfd = new SimpleDateFormat("dd");
        pager = new Pager(0);
        Company com = usersService.getCompanyByUser();

        Map<String,Object> paramsProBack = new HashMap<String,Object>();
        if(StringUtils.isNotEmpty(proInfoId)){
            ProInfo proInfo = proInfoService.get(proInfoId);
            paramsProBack.put("proInfo",proInfo);
        }
        paramsProBack.put("company",com);
        paramsProBack.put("regular",1);

        Pager pagerProback = proBackService.findByPagerAndCompany(pager,null,null,paramsProBack);
        List<ProBack>  proBackList = (List<ProBack>) pagerProback.getList();
        paramsProBack.put("regular",0);
        Pager pagerProback2 = proBackService.findByPagerAndCompany(pager,null,null,paramsProBack);
        List<ProBack>  proBackList2 = (List<ProBack>) pagerProback2.getList();

        List<JSONObject> dataList = new ArrayList<JSONObject>();
        List<JSONObject> dataList2 = new ArrayList<JSONObject>();
        List<JSONObject> dataList3 = new ArrayList<JSONObject>();
        List<JSONObject> dataList4 = new ArrayList<JSONObject>();
        List<JSONObject> dataList5 = new ArrayList<JSONObject>();

        List<JSONObject> rdataList = new ArrayList<JSONObject>();
        List<JSONObject> rdataList2 = new ArrayList<JSONObject>();
        List<JSONObject> rdataList3 = new ArrayList<JSONObject>();
        List<JSONObject> rdataList4 = new ArrayList<JSONObject>();
        List<JSONObject> rdataList5 = new ArrayList<JSONObject>();


        List<JSONObject> seriesList = new  ArrayList<JSONObject>();
        List<JSONObject> seriesList2 = new  ArrayList<JSONObject>();
        List<JSONObject> seriesList3 = new  ArrayList<JSONObject>();
        List<JSONObject> seriesList4 = new  ArrayList<JSONObject>();
        List<JSONObject> seriesList5 = new  ArrayList<JSONObject>();

        List<JSONObject> optionsList = new ArrayList<JSONObject>();
        Map<String, Object> xMap = new HashMap<String, Object>();
        Map<String, Object> xMap2 = new HashMap<String, Object>();
        Map<String, Object> xMap3 = new HashMap<String, Object>();
        Map<String, Object> xMap4 = new HashMap<String, Object>();
        Map<String, Object> xMap5 = new HashMap<String, Object>();

        Map<String, Object> rxMap = new HashMap<String, Object>();
        Map<String, Object> rxMap2 = new HashMap<String, Object>();
        Map<String, Object> rxMap3 = new HashMap<String, Object>();
        Map<String, Object> rxMap4 = new HashMap<String, Object>();
        Map<String, Object> rxMap5 = new HashMap<String, Object>();

        int yearInt = Integer.valueOf(year).intValue();
        for(ProBack back:proBackList) {
            Date createDate = back.getCreateDate();
            String yearStr = sdfy.format(createDate);
            String monthStr = sdfm.format(createDate);
            String dayStr = sdfd.format(createDate);
            int yearStrInt = Integer.valueOf(yearStr).intValue();

                //  System.out.println("monthStr:"+monthStr);
                if (yearStrInt == yearInt ) {
                    if (xMap.get(monthStr) == null) {
                        xMap.put(monthStr, 1);
                    }else{
                        xMap.put(monthStr, Integer.valueOf(xMap.get(monthStr).toString()).intValue() + 1);
                    }
                }else if(yearStrInt == yearInt-1 ){
                    if (xMap2.get(monthStr) == null) {
                        xMap2.put(monthStr, 1);
                    }else{
                        xMap2.put(monthStr, Integer.valueOf(xMap2.get(monthStr).toString()).intValue() + 1);
                    }
                }else if(yearStrInt == yearInt-2 ){
                    if (xMap3.get(monthStr) == null) {
                        xMap3.put(monthStr, 1);
                    }else{
                        xMap3.put(monthStr, Integer.valueOf(xMap3.get(monthStr).toString()).intValue() + 1);
                    }
                }else if(yearStrInt == yearInt-3 ){
                    if (xMap4.get(monthStr) == null) {
                        xMap4.put(monthStr, 1);
                    }else{
                        xMap4.put(monthStr, Integer.valueOf(xMap4.get(monthStr).toString()).intValue() + 1);
                    }
                }else if(yearStrInt == yearInt-4){
                    if (xMap5.get(monthStr) == null) {
                        xMap5.put(monthStr, 1);
                    }else{
                        xMap5.put(monthStr, Integer.valueOf(xMap5.get(monthStr).toString()).intValue() + 1);
                    }
                }

        }

        for(ProBack back:proBackList2) {
            Date createDate = back.getCreateDate();
            String yearStr = sdfy.format(createDate);
            String monthStr = sdfm.format(createDate);
            String dayStr = sdfd.format(createDate);
            int yearStrInt = Integer.valueOf(yearStr).intValue();

            //  System.out.println("monthStr:"+monthStr);
            if (yearStrInt == yearInt) {
                if (rxMap.get(monthStr) == null) {
                    rxMap.put(monthStr, 1);
                }else{
                    rxMap.put(monthStr, Integer.valueOf(rxMap.get(monthStr).toString()).intValue() + 1);
                }
            }else if(yearStrInt == yearInt-1 ){
                if (rxMap2.get(monthStr) == null) {
                    rxMap2.put(monthStr, 1);
                }else{
                    rxMap2.put(monthStr, Integer.valueOf(rxMap2.get(monthStr).toString()).intValue() + 1);
                }
            }else if(yearStrInt == yearInt-2 ){
                if (rxMap3.get(monthStr) == null) {
                    rxMap3.put(monthStr, 1);
                }else{
                    rxMap3.put(monthStr, Integer.valueOf(rxMap3.get(monthStr).toString()).intValue() + 1);
                }
            }else if(yearStrInt == yearInt-3 ){
                if (rxMap4.get(monthStr) == null) {
                    rxMap4.put(monthStr, 1);
                }else{
                    rxMap4.put(monthStr, Integer.valueOf(rxMap4.get(monthStr).toString()).intValue() + 1);
                }
            }else if(yearStrInt == yearInt-4 ){
                if (rxMap5.get(monthStr) == null) {
                    rxMap5.put(monthStr, 1);
                }else{
                    rxMap5.put(monthStr, Integer.valueOf(rxMap5.get(monthStr).toString()).intValue() + 1);
                }
            }
        }




        for(int i=1; i<=12; i++){
            Map<String, Object> iMap = new HashMap<String, Object>();
            Map<String, Object> iMap2 = new HashMap<String, Object>();
            Map<String, Object> iMap3 = new HashMap<String, Object>();
            Map<String, Object> iMap4 = new HashMap<String, Object>();
            Map<String, Object> iMap5 = new HashMap<String, Object>();

            Map<String, Object> riMap = new HashMap<String, Object>();
            Map<String, Object> riMap2 = new HashMap<String, Object>();
            Map<String, Object> riMap3 = new HashMap<String, Object>();
            Map<String, Object> riMap4 = new HashMap<String, Object>();
            Map<String, Object> riMap5 = new HashMap<String, Object>();

            if(xMap.containsKey(String.valueOf(i))){
                iMap.put(String.valueOf(i),xMap.get(String.valueOf(i)));
            }else{
                iMap.put(String.valueOf(i),0);
            }
            if(xMap2.containsKey(String.valueOf(i))){
                iMap2.put(String.valueOf(i),xMap2.get(String.valueOf(i)));
            }else{
                iMap2.put(String.valueOf(i),0);
            }
            if(xMap3.containsKey(String.valueOf(i))){
                iMap3.put(String.valueOf(i), xMap3.get(String.valueOf(i)));
            }else{
                iMap3.put(String.valueOf(i),0);
            }
            if(xMap4.containsKey(String.valueOf(i))){
                iMap4.put(String.valueOf(i),xMap4.get(String.valueOf(i)));
            }else{
                iMap4.put(String.valueOf(i),0);
            }
            if(xMap5.containsKey(String.valueOf(i))){
                iMap5.put(String.valueOf(i),xMap5.get(String.valueOf(i)));
            }else{
                iMap5.put(String.valueOf(i),0);
            }


            if(rxMap.containsKey(String.valueOf(i))){
                riMap.put(String.valueOf(i),rxMap.get(String.valueOf(i)));
            }else{
                riMap.put(String.valueOf(i),0);
            }
            if(rxMap2.containsKey(String.valueOf(i))){
                riMap2.put(String.valueOf(i),rxMap2.get(String.valueOf(i)));
            }else{
                riMap2.put(String.valueOf(i),0);
            }
            if(rxMap3.containsKey(String.valueOf(i))){
                riMap3.put(String.valueOf(i), rxMap3.get(String.valueOf(i)));
            }else{
                riMap3.put(String.valueOf(i),0);
            }
            if(rxMap4.containsKey(String.valueOf(i))){
                riMap4.put(String.valueOf(i),rxMap4.get(String.valueOf(i)));
            }else{
                riMap4.put(String.valueOf(i),0);
            }
            if(rxMap5.containsKey(String.valueOf(i))){
                riMap5.put(String.valueOf(i),rxMap5.get(String.valueOf(i)));
            }else{
                riMap5.put(String.valueOf(i),0);
            }

            dataList.add(JSONObject.fromObject(iMap));
            dataList2.add(JSONObject.fromObject(iMap2));
            dataList3.add(JSONObject.fromObject(iMap3));
            dataList4.add(JSONObject.fromObject(iMap4));
            dataList5.add(JSONObject.fromObject(iMap5));

            rdataList.add(JSONObject.fromObject(riMap));
            rdataList2.add(JSONObject.fromObject(riMap2));
            rdataList3.add(JSONObject.fromObject(riMap3));
            rdataList4.add(JSONObject.fromObject(riMap4));
            rdataList5.add(JSONObject.fromObject(riMap5));

        }

        Map<String, Object> dMap = new HashMap<String, Object>();
        dMap.put("data", dataList);
        seriesList.add(JSONObject.fromObject(dMap));
        Map<String, Object> rdMap = new HashMap<String, Object>();
        rdMap.put("data", rdataList);
        seriesList.add(JSONObject.fromObject(rdMap));

        Map<String, Object> dMap2 = new HashMap<String, Object>();
        dMap2.put("data", dataList2);
        seriesList2.add(JSONObject.fromObject(dMap2));
        Map<String, Object> rdMap2 = new HashMap<String, Object>();
        rdMap2.put("data", rdataList2);
        seriesList2.add(JSONObject.fromObject(rdMap2));

        Map<String, Object> dMap3 = new HashMap<String, Object>();
        dMap3.put("data", dataList3);
        seriesList3.add(JSONObject.fromObject(dMap3));
        Map<String, Object> rdMap3 = new HashMap<String, Object>();
        rdMap3.put("data", rdataList3);
        seriesList3.add(JSONObject.fromObject(rdMap3));

        Map<String, Object> dMap4 = new HashMap<String, Object>();
        dMap4.put("data", dataList4);
        seriesList4.add(JSONObject.fromObject(dMap4));
        Map<String, Object> rdMap4 = new HashMap<String, Object>();
        rdMap4.put("data", rdataList4);
        seriesList4.add(JSONObject.fromObject(rdMap4));

        Map<String, Object> dMap5 = new HashMap<String, Object>();
        dMap5.put("data", dataList5);
        seriesList5.add(JSONObject.fromObject(dMap5));
        Map<String, Object> rdMap5 = new HashMap<String, Object>();
        rdMap5.put("data", rdataList5);
        seriesList5.add(JSONObject.fromObject(rdMap5));



        Map<String, Object> sMap = new HashMap<String, Object>();
        sMap.put("series",seriesList);
        sMap.put("title",year+"年项目反馈数量");

        Map<String, Object> sMap2 = new HashMap<String, Object>();
        sMap2.put("series",seriesList2);
        sMap2.put("title", String.valueOf(yearInt-1)+"年项目反馈数量");

        Map<String, Object> sMap3 = new HashMap<String, Object>();
        sMap3.put("series",seriesList3);
        sMap3.put("title", String.valueOf(yearInt-2)+"年项目反馈数量");

        Map<String, Object> sMap4 = new HashMap<String, Object>();
        sMap4.put("series",seriesList4);
        sMap4.put("title", String.valueOf(yearInt-3)+"年项目反馈数量");

        Map<String, Object> sMap5 = new HashMap<String, Object>();
        sMap5.put("series",seriesList5);
        sMap5.put("title", String.valueOf(yearInt-4)+"年项目反馈数量");



        optionsList.add(JSONObject.fromObject(sMap));
        optionsList.add(JSONObject.fromObject(sMap2));
        optionsList.add(JSONObject.fromObject(sMap3));
        optionsList.add(JSONObject.fromObject(sMap4));
        optionsList.add(JSONObject.fromObject(sMap5));

        Map<String, Object> oMap = new HashMap<String, Object>();
        oMap.put("options",optionsList);
        String[] years = new String[]{year,String.valueOf(yearInt-1),String.valueOf(yearInt-2),String.valueOf(yearInt-3),String.valueOf(yearInt-4)};
        List<String> timeline = new ArrayList<String>(Arrays.asList(years));//横坐标
        oMap.put("timeline",timeline);
        return ajaxJson(JSONObject.fromObject(oMap).toString());
    }

    public String getChartData(){
        Date date = new Date();
        String year = DataUtil.DateToString(date, "yyyy");
        String month = DataUtil.DateToString(date, "M");
        String day = DataUtil.DateToString(date, "dd");
        String now = DataUtil.DateToString(date, "yyyy-MM-dd");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdfy = new SimpleDateFormat("yyyy");
        SimpleDateFormat sdfm = new SimpleDateFormat("M");
        SimpleDateFormat sdfd = new SimpleDateFormat("dd");
        pager = new Pager(0);
        Company com = usersService.getCompanyByUser();

        Map<String,Object> paramsProBack = new HashMap<String,Object>();
        if(StringUtils.isNotEmpty(proInfoId)){
            ProInfo proInfo = proInfoService.get(proInfoId);
            paramsProBack.put("proInfo",proInfo);
        }
        paramsProBack.put("company",com);
        paramsProBack.put("regular",1);

        Pager pagerProback = proBackService.findByPagerAndCompany(pager,null,null,paramsProBack);
        List<ProBack>  proBackList = (List<ProBack>) pagerProback.getList();
        paramsProBack.put("regular",0);
        Pager pagerProback2 = proBackService.findByPagerAndCompany(pager,null,null,paramsProBack);
        List<ProBack>  proBackList2 = (List<ProBack>) pagerProback2.getList();

        List<JSONObject> dataList = new ArrayList<JSONObject>();
        List<JSONObject> dataList2 = new ArrayList<JSONObject>();
        List<JSONObject> dataList3 = new ArrayList<JSONObject>();
        List<JSONObject> dataList4 = new ArrayList<JSONObject>();
        List<JSONObject> dataList5 = new ArrayList<JSONObject>();
        List<JSONObject> dataList6 = new ArrayList<JSONObject>();
        List<JSONObject> dataList7 = new ArrayList<JSONObject>();
        List<JSONObject> dataList8 = new ArrayList<JSONObject>();
        List<JSONObject> dataList9 = new ArrayList<JSONObject>();
        List<JSONObject> dataList10 = new ArrayList<JSONObject>();
        List<JSONObject> dataList11 = new ArrayList<JSONObject>();
        List<JSONObject> dataList12 = new ArrayList<JSONObject>();
        List<JSONObject> rdataList = new ArrayList<JSONObject>();
        List<JSONObject> rdataList2 = new ArrayList<JSONObject>();
        List<JSONObject> rdataList3 = new ArrayList<JSONObject>();
        List<JSONObject> rdataList4 = new ArrayList<JSONObject>();
        List<JSONObject> rdataList5 = new ArrayList<JSONObject>();
        List<JSONObject> rdataList6 = new ArrayList<JSONObject>();
        List<JSONObject> rdataList7 = new ArrayList<JSONObject>();
        List<JSONObject> rdataList8 = new ArrayList<JSONObject>();
        List<JSONObject> rdataList9 = new ArrayList<JSONObject>();
        List<JSONObject> rdataList10 = new ArrayList<JSONObject>();
        List<JSONObject> rdataList11 = new ArrayList<JSONObject>();
        List<JSONObject> rdataList12 = new ArrayList<JSONObject>();

        List<JSONObject> seriesList = new  ArrayList<JSONObject>();
        List<JSONObject> seriesList2 = new  ArrayList<JSONObject>();
        List<JSONObject> seriesList3 = new  ArrayList<JSONObject>();
        List<JSONObject> seriesList4 = new  ArrayList<JSONObject>();
        List<JSONObject> seriesList5 = new  ArrayList<JSONObject>();
        List<JSONObject> seriesList6 = new  ArrayList<JSONObject>();
        List<JSONObject> seriesList7 = new  ArrayList<JSONObject>();
        List<JSONObject> seriesList8 = new  ArrayList<JSONObject>();
        List<JSONObject> seriesList9 = new  ArrayList<JSONObject>();
        List<JSONObject> seriesList10 = new  ArrayList<JSONObject>();
        List<JSONObject> seriesList11 = new  ArrayList<JSONObject>();
        List<JSONObject> seriesList12 = new  ArrayList<JSONObject>();
        List<JSONObject> optionsList = new ArrayList<JSONObject>();
        Map<String, Object> xMap = new HashMap<String, Object>();
        Map<String, Object> xMap2 = new HashMap<String, Object>();
        Map<String, Object> xMap3 = new HashMap<String, Object>();
        Map<String, Object> xMap4 = new HashMap<String, Object>();
        Map<String, Object> xMap5 = new HashMap<String, Object>();
        Map<String, Object> xMap6 = new HashMap<String, Object>();
        Map<String, Object> xMap7 = new HashMap<String, Object>();
        Map<String, Object> xMap8 = new HashMap<String, Object>();
        Map<String, Object> xMap9 = new HashMap<String, Object>();
        Map<String, Object> xMap10 = new HashMap<String, Object>();
        Map<String, Object> xMap11 = new HashMap<String, Object>();
        Map<String, Object> xMap12 = new HashMap<String, Object>();
        Map<String, Object> rxMap = new HashMap<String, Object>();
        Map<String, Object> rxMap2 = new HashMap<String, Object>();
        Map<String, Object> rxMap3 = new HashMap<String, Object>();
        Map<String, Object> rxMap4 = new HashMap<String, Object>();
        Map<String, Object> rxMap5 = new HashMap<String, Object>();
        Map<String, Object> rxMap6 = new HashMap<String, Object>();
        Map<String, Object> rxMap7 = new HashMap<String, Object>();
        Map<String, Object> rxMap8 = new HashMap<String, Object>();
        Map<String, Object> rxMap9 = new HashMap<String, Object>();
        Map<String, Object> rxMap10 = new HashMap<String, Object>();
        Map<String, Object> rxMap11 = new HashMap<String, Object>();
        Map<String, Object> rxMap12 = new HashMap<String, Object>();

        for(ProBack back:proBackList) {
            Date createDate = back.getCreateDate();
            String yearStr = sdfy.format(createDate);
            String monthStr = sdfm.format(createDate);
            String dayStr = sdfd.format(createDate);
            if(yearStr.equals(year)) {
              //  System.out.println("monthStr:"+monthStr);
                if (monthStr.equals("1")) {
                    if (xMap.get(dayStr) == null) {
                        xMap.put(dayStr, 1);
                    }else{
                        xMap.put(dayStr, Integer.valueOf(xMap.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("2")){
                    if (xMap2.get(dayStr) == null) {
                        xMap2.put(dayStr, 1);
                    }else{
                        xMap2.put(dayStr, Integer.valueOf(xMap2.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("3")){
                    if (xMap3.get(dayStr) == null) {
                        xMap3.put(dayStr, 1);
                    }else{
                        xMap3.put(dayStr, Integer.valueOf(xMap3.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("4")){
                    if (xMap4.get(dayStr) == null) {
                        xMap4.put(dayStr, 1);
                    }else{
                        xMap4.put(dayStr, Integer.valueOf(xMap4.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("5")){
                    if (xMap5.get(dayStr) == null) {
                        xMap5.put(dayStr, 1);
                    }else{
                        xMap5.put(dayStr, Integer.valueOf(xMap5.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("6")){
                    // System.out.println("dayStr:"+dayStr);
                    if (xMap6.get(dayStr) == null) {
                        xMap6.put(dayStr, 1);
                    }else{
                        xMap6.put(dayStr, Integer.valueOf(xMap6.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("7")){
                    if (xMap7.get(dayStr) == null) {
                        xMap7.put(dayStr, 1);
                    }else{
                        xMap7.put(dayStr, Integer.valueOf(xMap7.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("8")){
                    if (xMap8.get(dayStr) == null) {
                        xMap8.put(dayStr, 1);
                    }else{
                        xMap8.put(dayStr, Integer.valueOf(xMap8.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("9")){
                    if (xMap9.get(dayStr) == null) {
                        xMap9.put(dayStr, 1);
                    }else{
                        xMap9.put(dayStr, Integer.valueOf(xMap9.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("10")){
                    if (xMap10.get(dayStr) == null) {
                        xMap10.put(dayStr, 1);
                    }else{
                        xMap10.put(dayStr, Integer.valueOf(xMap10.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("11")){
                    if (xMap11.get(dayStr) == null) {
                        xMap11.put(dayStr,1);
                    }else{
                        xMap11.put(dayStr, Integer.valueOf(xMap11.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("12")){
                    if (xMap12.get(dayStr) == null) {
                        xMap12.put(dayStr, 1);
                    }else{
                        xMap12.put(dayStr, Integer.valueOf(xMap12.get(dayStr).toString()).intValue() + 1);
                    }
                }
            }
        }

        for(ProBack back:proBackList2) {
            Date createDate = back.getCreateDate();
            String yearStr = sdfy.format(createDate);
            String monthStr = sdfm.format(createDate);
            String dayStr = sdfd.format(createDate);
            if(yearStr.equals(year)) {
                //  System.out.println("monthStr:"+monthStr);
                if (monthStr.equals("1")) {
                    if (rxMap.get(dayStr) == null) {
                        rxMap.put(dayStr, 1);
                    }else{
                        rxMap.put(dayStr, Integer.valueOf(rxMap.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("2")){
                    if (rxMap2.get(dayStr) == null) {
                        rxMap2.put(dayStr, 1);
                    }else{
                        rxMap2.put(dayStr, Integer.valueOf(rxMap2.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("3")){
                    if (rxMap3.get(dayStr) == null) {
                        rxMap3.put(dayStr, 1);
                    }else{
                        rxMap3.put(dayStr, Integer.valueOf(rxMap3.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("4")){
                    if (rxMap4.get(dayStr) == null) {
                        rxMap4.put(dayStr, 1);
                    }else{
                        rxMap4.put(dayStr, Integer.valueOf(rxMap4.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("5")){
                    if (rxMap5.get(dayStr) == null) {
                        rxMap5.put(dayStr, 1);
                    }else{
                        rxMap5.put(dayStr, Integer.valueOf(rxMap5.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("6")){
                    // System.out.println("dayStr:"+dayStr);
                    if (rxMap6.get(dayStr) == null) {
                        rxMap6.put(dayStr, 1);
                    }else{
                        rxMap6.put(dayStr, Integer.valueOf(rxMap6.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("7")){
                    if (rxMap7.get(dayStr) == null) {
                        rxMap7.put(dayStr, 1);
                    }else{
                        rxMap7.put(dayStr, Integer.valueOf(rxMap7.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("8")){
                    if (rxMap8.get(dayStr) == null) {
                        rxMap8.put(dayStr, 1);
                    }else{
                        rxMap8.put(dayStr, Integer.valueOf(rxMap8.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("9")){
                    if (rxMap9.get(dayStr) == null) {
                        rxMap9.put(dayStr, 1);
                    }else{
                        rxMap9.put(dayStr, Integer.valueOf(rxMap9.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("10")){
                    if (rxMap10.get(dayStr) == null) {
                        rxMap10.put(dayStr, 1);
                    }else{
                        rxMap10.put(dayStr, Integer.valueOf(rxMap10.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("11")){
                    if (rxMap11.get(dayStr) == null) {
                        rxMap11.put(dayStr,1);
                    }else{
                        rxMap11.put(dayStr, Integer.valueOf(rxMap11.get(dayStr).toString()).intValue() + 1);
                    }
                }else if(monthStr.equals("12")){
                    if (rxMap12.get(dayStr) == null) {
                        rxMap12.put(dayStr, 1);
                    }else{
                        rxMap12.put(dayStr, Integer.valueOf(rxMap12.get(dayStr).toString()).intValue() + 1);
                    }
                }
            }
        }

        /*
        for(Map.Entry<String, Object> entry:xMap6.entrySet()){
            System.out.println("6月正常key:"+entry.getKey()+",value:"+entry.getValue());
        }
        for(Map.Entry<String, Object> entry:rxMap6.entrySet()){
            System.out.println("6月非正常key:"+entry.getKey()+",value:"+entry.getValue());
        }
        for(Map.Entry<String, Object> entry:xMap7.entrySet()){
            System.out.println("7月正常key:"+entry.getKey()+",value:"+entry.getValue());
        }
        for(Map.Entry<String, Object> entry:rxMap7.entrySet()){
            System.out.println("7月非正常key:"+entry.getKey()+",value:"+entry.getValue());
        }*/
        for(int i=1; i<=31; i++){
            Map<String, Object> iMap = new HashMap<String, Object>();
            Map<String, Object> iMap2 = new HashMap<String, Object>();
            Map<String, Object> iMap3 = new HashMap<String, Object>();
            Map<String, Object> iMap4 = new HashMap<String, Object>();
            Map<String, Object> iMap5 = new HashMap<String, Object>();
            Map<String, Object> iMap6 = new HashMap<String, Object>();
            Map<String, Object> iMap7 = new HashMap<String, Object>();
            Map<String, Object> iMap8 = new HashMap<String, Object>();
            Map<String, Object> iMap9 = new HashMap<String, Object>();
            Map<String, Object> iMap10 = new HashMap<String, Object>();
            Map<String, Object> iMap11 = new HashMap<String, Object>();
            Map<String, Object> iMap12 = new HashMap<String, Object>();
            Map<String, Object> riMap = new HashMap<String, Object>();
            Map<String, Object> riMap2 = new HashMap<String, Object>();
            Map<String, Object> riMap3 = new HashMap<String, Object>();
            Map<String, Object> riMap4 = new HashMap<String, Object>();
            Map<String, Object> riMap5 = new HashMap<String, Object>();
            Map<String, Object> riMap6 = new HashMap<String, Object>();
            Map<String, Object> riMap7 = new HashMap<String, Object>();
            Map<String, Object> riMap8 = new HashMap<String, Object>();
            Map<String, Object> riMap9 = new HashMap<String, Object>();
            Map<String, Object> riMap10 = new HashMap<String, Object>();
            Map<String, Object> riMap11 = new HashMap<String, Object>();
            Map<String, Object> riMap12 = new HashMap<String, Object>();
            if(xMap.containsKey(String.valueOf(i))){
                iMap.put(String.valueOf(i),xMap.get(String.valueOf(i)));
            }else{
                iMap.put(String.valueOf(i),0);
            }
            if(xMap2.containsKey(String.valueOf(i))){
                iMap2.put(String.valueOf(i),xMap2.get(String.valueOf(i)));
            }else{
                iMap2.put(String.valueOf(i),0);
            }
            if(xMap3.containsKey(String.valueOf(i))){
                iMap3.put(String.valueOf(i), xMap3.get(String.valueOf(i)));
            }else{
                iMap3.put(String.valueOf(i),0);
            }
            if(xMap4.containsKey(String.valueOf(i))){
                iMap4.put(String.valueOf(i),xMap4.get(String.valueOf(i)));
            }else{
                iMap4.put(String.valueOf(i),0);
            }
            if(xMap5.containsKey(String.valueOf(i))){
                iMap5.put(String.valueOf(i),xMap5.get(String.valueOf(i)));
            }else{
                iMap5.put(String.valueOf(i),0);
            }
            if(xMap6.containsKey(String.valueOf(i))){
               // System.out.println("do:"+ xMap6.get(String.valueOf(i)));
                iMap6.put(String.valueOf(i),xMap6.get(String.valueOf(i)));
            }else{
                iMap6.put(String.valueOf(i),0);
            }
            if(xMap7.containsKey(String.valueOf(i))){
                iMap7.put(String.valueOf(i),xMap7.get(String.valueOf(i)));
            }else{
                iMap7.put(String.valueOf(i),0);
            }
            if(xMap8.containsKey(String.valueOf(i))){
                iMap8.put(String.valueOf(i),xMap8.get(String.valueOf(i)));
            }else{
                iMap8.put(String.valueOf(i),0);
            }
            if(xMap9.containsKey(String.valueOf(i))){
                iMap9.put(String.valueOf(i),xMap9.get(String.valueOf(i)));
            }else{
                iMap9.put(String.valueOf(i),0);
            }
            if(xMap10.containsKey(String.valueOf(i))){
                iMap10.put(String.valueOf(i),xMap10.get(String.valueOf(i)));
            }else{
                iMap10.put(String.valueOf(i),0);
            }
            if(xMap11.containsKey(String.valueOf(i))){
                iMap11.put(String.valueOf(i),xMap11.get(String.valueOf(i)));
            }else{
                iMap11.put(String.valueOf(i),0);
            }
            if(xMap12.containsKey(String.valueOf(i))){
                iMap12.put(String.valueOf(i),xMap12.get(String.valueOf(i)));
            }else{
                iMap12.put(String.valueOf(i),0);
            }

            if(rxMap.containsKey(String.valueOf(i))){
                riMap.put(String.valueOf(i),rxMap.get(String.valueOf(i)));
            }else{
                riMap.put(String.valueOf(i),0);
            }
            if(rxMap2.containsKey(String.valueOf(i))){
                riMap2.put(String.valueOf(i),rxMap2.get(String.valueOf(i)));
            }else{
                riMap2.put(String.valueOf(i),0);
            }
            if(rxMap3.containsKey(String.valueOf(i))){
                riMap3.put(String.valueOf(i), rxMap3.get(String.valueOf(i)));
            }else{
                riMap3.put(String.valueOf(i),0);
            }
            if(rxMap4.containsKey(String.valueOf(i))){
                riMap4.put(String.valueOf(i),rxMap4.get(String.valueOf(i)));
            }else{
                riMap4.put(String.valueOf(i),0);
            }
            if(rxMap5.containsKey(String.valueOf(i))){
                riMap5.put(String.valueOf(i),rxMap5.get(String.valueOf(i)));
            }else{
                riMap5.put(String.valueOf(i),0);
            }
            if(rxMap6.containsKey(String.valueOf(i))){
                // System.out.println("do:"+ xMap6.get(String.valueOf(i)));
                riMap6.put(String.valueOf(i),rxMap6.get(String.valueOf(i)));
            }else{
                riMap6.put(String.valueOf(i),0);
            }
            if(rxMap7.containsKey(String.valueOf(i))){
                riMap7.put(String.valueOf(i),rxMap7.get(String.valueOf(i)));
            }else{
                riMap7.put(String.valueOf(i),0);
            }
            if(rxMap8.containsKey(String.valueOf(i))){
                riMap8.put(String.valueOf(i),rxMap8.get(String.valueOf(i)));
            }else{
                riMap8.put(String.valueOf(i),0);
            }
            if(rxMap9.containsKey(String.valueOf(i))){
                riMap9.put(String.valueOf(i),rxMap9.get(String.valueOf(i)));
            }else{
                riMap9.put(String.valueOf(i),0);
            }
            if(rxMap10.containsKey(String.valueOf(i))){
                riMap10.put(String.valueOf(i),rxMap10.get(String.valueOf(i)));
            }else{
                riMap10.put(String.valueOf(i),0);
            }
            if(rxMap11.containsKey(String.valueOf(i))){
                riMap11.put(String.valueOf(i),rxMap11.get(String.valueOf(i)));
            }else{
                riMap11.put(String.valueOf(i),0);
            }
            if(rxMap12.containsKey(String.valueOf(i))){
                riMap12.put(String.valueOf(i),rxMap12.get(String.valueOf(i)));
            }else{
                riMap12.put(String.valueOf(i),0);
            }
            dataList.add(JSONObject.fromObject(iMap));
            dataList2.add(JSONObject.fromObject(iMap2));
            dataList3.add(JSONObject.fromObject(iMap3));
            dataList4.add(JSONObject.fromObject(iMap4));
            dataList5.add(JSONObject.fromObject(iMap5));
            dataList6.add(JSONObject.fromObject(iMap6));
            dataList7.add(JSONObject.fromObject(iMap7));
            dataList8.add(JSONObject.fromObject(iMap8));
            dataList9.add(JSONObject.fromObject(iMap9));
            dataList10.add(JSONObject.fromObject(iMap10));
            dataList11.add(JSONObject.fromObject(iMap11));
            dataList12.add(JSONObject.fromObject(iMap12));

            rdataList.add(JSONObject.fromObject(riMap));
            rdataList2.add(JSONObject.fromObject(riMap2));
            rdataList3.add(JSONObject.fromObject(riMap3));
            rdataList4.add(JSONObject.fromObject(riMap4));
            rdataList5.add(JSONObject.fromObject(riMap5));
            rdataList6.add(JSONObject.fromObject(riMap6));
            rdataList7.add(JSONObject.fromObject(riMap7));
            rdataList8.add(JSONObject.fromObject(riMap8));
            rdataList9.add(JSONObject.fromObject(riMap9));
            rdataList10.add(JSONObject.fromObject(riMap10));
            rdataList11.add(JSONObject.fromObject(riMap11));
            rdataList12.add(JSONObject.fromObject(riMap12));
        }

        Map<String, Object> dMap = new HashMap<String, Object>();
        dMap.put("data", dataList);
        seriesList.add(JSONObject.fromObject(dMap));
        Map<String, Object> rdMap = new HashMap<String, Object>();
        rdMap.put("data", rdataList);
        seriesList.add(JSONObject.fromObject(rdMap));

        Map<String, Object> dMap2 = new HashMap<String, Object>();
        dMap2.put("data", dataList2);
        seriesList2.add(JSONObject.fromObject(dMap2));
        Map<String, Object> rdMap2 = new HashMap<String, Object>();
        rdMap2.put("data", rdataList2);
        seriesList2.add(JSONObject.fromObject(rdMap2));

        Map<String, Object> dMap3 = new HashMap<String, Object>();
        dMap3.put("data", dataList3);
        seriesList3.add(JSONObject.fromObject(dMap3));
        Map<String, Object> rdMap3 = new HashMap<String, Object>();
        rdMap3.put("data", rdataList3);
        seriesList3.add(JSONObject.fromObject(rdMap3));

        Map<String, Object> dMap4 = new HashMap<String, Object>();
        dMap4.put("data", dataList4);
        seriesList4.add(JSONObject.fromObject(dMap4));
        Map<String, Object> rdMap4 = new HashMap<String, Object>();
        rdMap4.put("data", rdataList4);
        seriesList4.add(JSONObject.fromObject(rdMap4));

        Map<String, Object> dMap5 = new HashMap<String, Object>();
        dMap5.put("data", dataList5);
        seriesList5.add(JSONObject.fromObject(dMap5));
        Map<String, Object> rdMap5 = new HashMap<String, Object>();
        rdMap5.put("data", rdataList5);
        seriesList5.add(JSONObject.fromObject(rdMap5));

        Map<String, Object> dMap6 = new HashMap<String, Object>();
        dMap6.put("data", dataList6);
        seriesList6.add(JSONObject.fromObject(dMap6));
        Map<String, Object> rdMap6 = new HashMap<String, Object>();
        rdMap6.put("data", rdataList6);
        seriesList6.add(JSONObject.fromObject(rdMap6));

        Map<String, Object> dMap7 = new HashMap<String, Object>();
        dMap7.put("data", dataList7);
        seriesList7.add(JSONObject.fromObject(dMap7));
        Map<String, Object> rdMap7 = new HashMap<String, Object>();
        rdMap7.put("data", rdataList7);
        seriesList7.add(JSONObject.fromObject(rdMap7));


        Map<String, Object> dMap8 = new HashMap<String, Object>();
        dMap8.put("data", dataList8);
        seriesList8.add(JSONObject.fromObject(dMap8));
        Map<String, Object> rdMap8 = new HashMap<String, Object>();
        rdMap8.put("data", rdataList8);
        seriesList8.add(JSONObject.fromObject(rdMap8));

        Map<String, Object> dMap9 = new HashMap<String, Object>();
        dMap9.put("data", dataList9);
        seriesList9.add(JSONObject.fromObject(dMap9));
        Map<String, Object> rdMap9 = new HashMap<String, Object>();
        rdMap9.put("data", rdataList9);
        seriesList9.add(JSONObject.fromObject(rdMap9));

        Map<String, Object> dMap10 = new HashMap<String, Object>();
        dMap10.put("data", dataList10);
        seriesList10.add(JSONObject.fromObject(dMap10));
        Map<String, Object> rdMap10 = new HashMap<String, Object>();
        rdMap10.put("data", rdataList10);
        seriesList10.add(JSONObject.fromObject(rdMap10));

        Map<String, Object> dMap11 = new HashMap<String, Object>();
        dMap11.put("data", dataList11);
        seriesList11.add(JSONObject.fromObject(dMap11));
        Map<String, Object> rdMap11 = new HashMap<String, Object>();
        rdMap11.put("data", rdataList11);
        seriesList11.add(JSONObject.fromObject(rdMap11));

        Map<String, Object> dMap12 = new HashMap<String, Object>();
        dMap12.put("data", dataList12);
        seriesList12.add(JSONObject.fromObject(dMap12));
        Map<String, Object> rdMap12 = new HashMap<String, Object>();
        rdMap12.put("data", rdataList12);
        seriesList12.add(JSONObject.fromObject(rdMap12));

        Map<String, Object> sMap = new HashMap<String, Object>();
        sMap.put("series",seriesList);
        sMap.put("title", year+"年1月项目反馈数量");

        Map<String, Object> sMap2 = new HashMap<String, Object>();
        sMap2.put("series",seriesList2);
        sMap2.put("title", year+"年2月项目反馈数量");

        Map<String, Object> sMap3 = new HashMap<String, Object>();
        sMap3.put("series",seriesList3);
        sMap3.put("title", year+"年3月项目反馈数量");

        Map<String, Object> sMap4 = new HashMap<String, Object>();
        sMap4.put("series",seriesList4);
        sMap4.put("title", year+"年4月项目反馈数量");

        Map<String, Object> sMap5 = new HashMap<String, Object>();
        sMap5.put("series",seriesList5);
        sMap5.put("title", year+"年5月项目反馈数量");

        Map<String, Object> sMap6 = new HashMap<String, Object>();
        sMap6.put("series",seriesList6);
        sMap6.put("title", year+"年6月项目反馈数量");

        Map<String, Object> sMap7 = new HashMap<String, Object>();
        sMap7.put("series",seriesList7);
        sMap7.put("title", year+"年7月项目反馈数量");

        Map<String, Object> sMap8 = new HashMap<String, Object>();
        sMap8.put("series",seriesList8);
        sMap8.put("title", year+"年8月项目反馈数量");

        Map<String, Object> sMap9 = new HashMap<String, Object>();
        sMap9.put("series",seriesList9);
        sMap9.put("title", year+"年9月项目反馈数量");

        Map<String, Object> sMap10 = new HashMap<String, Object>();
        sMap10.put("series",seriesList10);
        sMap10.put("title", year+"年10月项目反馈数量");

        Map<String, Object> sMap11 = new HashMap<String, Object>();
        sMap11.put("series",seriesList11);
        sMap11.put("title", year+"年11月项目反馈数量");

        Map<String, Object> sMap12 = new HashMap<String, Object>();
        sMap12.put("series",seriesList12);
        sMap12.put("title", year+"年12月项目反馈数量");

        optionsList.add(JSONObject.fromObject(sMap));
        optionsList.add(JSONObject.fromObject(sMap2));
        optionsList.add(JSONObject.fromObject(sMap3));
        optionsList.add(JSONObject.fromObject(sMap4));
        optionsList.add(JSONObject.fromObject(sMap5));
        optionsList.add(JSONObject.fromObject(sMap6));
        optionsList.add(JSONObject.fromObject(sMap7));
        optionsList.add(JSONObject.fromObject(sMap8));
        optionsList.add(JSONObject.fromObject(sMap9));
        optionsList.add(JSONObject.fromObject(sMap10));
        optionsList.add(JSONObject.fromObject(sMap11));
        optionsList.add(JSONObject.fromObject(sMap12));
        Map<String, Object> oMap = new HashMap<String, Object>();
        oMap.put("options",optionsList);
        return ajaxJson(JSONObject.fromObject(oMap).toString());
    }

    @Override
    public String getKeyId() {
        return keyId;
    }

    @Override
    public void setKeyId(String keyId) {
        this.keyId = keyId;
    }

    public String getProInfoId() {
        return proInfoId;
    }

    public void setProInfoId(String proInfoId) {
        this.proInfoId = proInfoId;
    }

    public ArrayList<Map<String, Object>> getTypesArrayList() {
        return typesArrayList;
    }

    public void setTypesArrayList(ArrayList<Map<String, Object>> typesArrayList) {
        this.typesArrayList = typesArrayList;
    }

    public String getDictId() {
        return dictId;
    }

    public void setDictId(String dictId) {
        this.dictId = dictId;
    }

    public Set<Users> getNotice() {
        return notice;
    }

    public void setNotice(Set<Users> notice) {
        this.notice = notice;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getMark() {
        return mark;
    }

    public void setMark(String mark) {
        this.mark = mark;
    }

    public int getRegular() {
        return regular;
    }

    public void setRegular(int regular) {
        this.regular = regular;
    }

    public ProBack getProBack() {
        return proBack;
    }

    public void setProBack(ProBack proBack) {
        this.proBack = proBack;
    }

    public String getCreateDate() {
        return createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    public String getNoticeId() {
        return noticeId;
    }

    public void setNoticeId(String noticeId) {
        this.noticeId = noticeId;
    }

    public Date getBackDate() {
        return backDate;
    }

    public void setBackDate(Date backDate) {
        this.backDate = backDate;
    }

    public String getViewType() {
        return viewType;
    }

    public void setViewType(String viewType) {
        this.viewType = viewType;
    }

    public Set<String> getImgUrl() {
        return imgUrl;
    }

    public void setImgUrl(Set<String> imgUrl) {
        this.imgUrl = imgUrl;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Users> getUsersList() {
        return usersList;
    }

    public void setUsersList(List<Users> usersList) {
        this.usersList = usersList;
    }

    public List<ProInfo> getProInfoList() {
        return proInfoList;
    }

    public void setProInfoList(List<ProInfo> proInfoList) {
        this.proInfoList = proInfoList;
    }

    public String getStart() {
        return start;
    }

    public void setStart(String start) {
        this.start = start;
    }

    public String getEnd() {
        return end;
    }

    public void setEnd(String end) {
        this.end = end;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public List<Dict> getProbackType() {
        return probackType;
    }

    public void setProbackType(List<Dict> probackType) {
        this.probackType = probackType;
    }

    public String getProbackTypeId() {
        return probackTypeId;
    }

    public void setProbackTypeId(String probackTypeId) {
        this.probackTypeId = probackTypeId;
    }
    public String getNow() {
        return now;
    }

    public void setNow(String now) {
        this.now = now;
    }

}
